<? require("adm_header.php"); ?>
<? 
writeCommonAdminTable(LA_ADMIN_COMMENTS_ADMIN,1);
$tplPackages = new tplLoad();
$lLimit = 6;

if (empty($offset))
	$offset=0;
		
if (getParam("del_id","")>0)
{
	if (getParam("confirmed","")==1)
	{
		q("delete from $com_tbl where comment_id=" . getParam("del_id",""));
		$tplPackages->assign("delete_complete",getParam("del_id",""));
	}
	else 
	{
		$tplPackages->assign("delete_confirm",getParam("del_id",""));
	}
}
if (getParam("submit",""))
{
	$lString=getParam("searchstring","");
	$lType=getParam("searchType","");
	if ($lString)
		$lSearchLimiter=" AND (comment_body like '%$lString%' OR comment_id='$lString' OR comment_ad='$lString' OR user_name like '%$lString%' OR comment_ip='$lString') ";
	if ($lType=="1")
		$lSearchLimiter.=" AND comment_user IS NULL";
	else if ($lType=="2")
		$lSearchLimiter.=" AND comment_ad IS NULL";
}


// Get total count
$sql_select = "select count(comment_id) as num_rows from $com_tbl,$usr_tbl where user_id=comment_userid $lSearchLimiter";  
$num_res=q($sql_select);
$lNumAds_row = mysql_fetch_array($num_res);
$lNumAds=$lNumAds_row["num_rows"];
$retArray=urlBar($lNumAds,$lLimit,getParam("page",1),getAllParams(array("page","delete","make_vendor","searchType")) . "&searchType=" . getParam("searchType",""));
$sql_limit=$retArray["sql_limit"];

$tplPackages->assign("num_ads",$lNumAds);
$sql_select = "select * from $com_tbl,$usr_tbl WHERE user_id=comment_userid  $lSearchLimiter order by comment_id desc $sql_limit";  

$result = q ($sql_select);
$lTypes[2]=LA_ADMIN_COMMENTS_USERS;
$lTypes[1]=LA_ADMIN_COMMENTS_ADS;
$tplPackages->assign("list",getDDFromList($lTypes,getParam("searchType",1)));
$i=0;	
while ($row = mysql_fetch_array($result))
{
	$lUserArray[$i]["comment_id"]=$row["comment_id"];
	$lUserArray[$i]["comment_body"]=strEnc($row["comment_body"]);
	$lUserArray[$i]["comment_username"]=strEnc($row["user_name"]);
	$lUserArray[$i]["comment_userid"]=$row["comment_userid"];
	$lUserArray[$i]["comment_ip"]=$row["comment_ip"];
	$lUserArray[$i]["comment_date"]=formatDateShort($row["comment_date"]);
	$lUserArray[$i]["comment_ad"]=$row["comment_ad"];
	
	$color=colorSwitch($color);	
	$lUserArray[$i]["color"]=$color;
	$lUserArray[$i]["NB"]=$i;
    $i++;
    
	
	$tplPackages->assign("url_bar",$retArray["url_bar"]);
}
$tplPackages->assign("searchstring",$lString);
$tplPackages->assign("listArray",$lUserArray);
$tplPackages->display("adm_comments.tpl");
writeCommonAdminTable("User Administration","");
require("adm_footer.php"); 
?>
